package cn.itcast.bos.web.action.take_delivery;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.aspectj.internal.lang.annotation.ajcDeclareAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.take_delivery.Order;
import cn.itcast.bos.service.take_delivery.OrderService;
import cn.itcast.bos.web.action.common.BaseAction;

@Controller
@Namespace("/")
@Scope("prototype")
@ParentPackage("json-default")
@SuppressWarnings("all")
public class OrderAction  extends BaseAction<Order>{

	@Autowired
	private OrderService orderService;
	
	/***
	 * 根据页面传递过来的订单id，去数据库找对应的数据信息
	 * order_findByOrderNum
	 */
	
	@Action(value="order_findByOrderNum",results={@Result(name="success",type="json")})
	public String findByOrderNum(){
		
	//调用业务层处理业务操作
	Order order=orderService.findByOrderNum(model.getOrderNum());
	
	//将结果封装到集合里面
	Map<String ,Object> map=new HashMap<String ,Object>();
	
	//判断是能找到对应的order信息
	if(order==null){
	//此时订单不存在
		map.put("success", false);
		
	}else{
	//订单存在
	map.put("success", true);
	map.put("orderData", order);
		
	}
	
	//将结果存入值栈
	ActionContext.getContext().getValueStack().push(map);
	
	return SUCCESS;
	}
	
	
	
}
